<%@page import="com.zhuoshi.bean.ManagerRoleValueBean"%>
<%@page import="com.zhuoshi.bean.ManagerRoleBean"%>
<%@page import="com.zhuoshi.dao.ManagerRoleDao"%>
<%@page import="com.zhuoshi.dao.NavigationDao"%>
<%@page import="com.zhuoshi.bean.NavigationBean"%>
<%@page import="com.zhuoshi.bean.ManagerBean"%>
<%@page import="com.zhuoshi.bean.ActionType"%>
<%@ page language="java" import="java.util.*,com.zhuoshi.utils.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%

	String t=request.getParameter("t");
	if("save".equals(t)){
		String[] role_value = request.getParameterValues("role_value");
		for(String str : role_value)
		out.print(str+",<br/>");
	}



String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String encryptMD5 = DESEncrypt.encryptMD5("admin");
pageContext.setAttribute("md5", encryptMD5);

//===============获取所有定义的枚举权限，并放到checkbox中以备后用===============//
List<ActionType> list = Utils.actionType();
pageContext.setAttribute("list", list);
//===========================================================================//
ManagerBean mBean = (ManagerBean)session.getAttribute("loginBean");
pageContext.setAttribute("bean", mBean); //把登录用户的实体信息  放入session中  并把这个session给到本也面的一个实体 
//===========================================================================



//List<NavigationBean> childList = new ArrayList<NavigationBean>();



/* String roleName = roleDao.getRoleName(3);
pageContext.setAttribute("roleName", roleName); */

/*==================
*根据登录用户的role_id判断    测试用   没啥用  获取一个角色实体  
*重要的是角色实体中有一个属性是 manager_role_valus 
*它获取的是manager_role_value表中相关角色的菜单和权限action_type
===============================*/
ManagerRoleDao roleDao = new ManagerRoleDao();
ManagerRoleBean roleBean = new ManagerRoleBean();
/* if(mBean.getRole_id()==1){
roleBean = roleDao.getModel(1);
}else{
	roleBean = roleDao.getModel(mBean.getRole_id());
} */
roleBean = roleDao.getModel(mBean.getRole_id());
pageContext.setAttribute("roleBean", roleBean);
//================================================//
/* if(roleBean.getManager_role_values().size()>0){
	out.print("有权限值");
}else{
	out.print("没有权限值，但是不是null");
} */
List<ManagerRoleValueBean> roleList = roleBean.getManager_role_values();
pageContext.setAttribute("roleList", roleList);


NavigationDao navDao = new NavigationDao();
List<NavigationBean> navList = new ArrayList<NavigationBean>();
if(mBean.getRole_id()==1){
//navList = navDao.getAllList(0);
}else{
	for(ManagerRoleValueBean bean : roleList){
		NavigationBean navBean = navDao.getModel(bean.getNav_id());
		navList.add(navBean);
	}
	
}
pageContext.setAttribute("navList", navList);



%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
</head>

<body>
	MD5加密后字符串： ${md5 }
	<br>
	<%=Utils.delLastComma("adf,fds,af,ds,afdsa,f,da,fd,asf,da,") %>
	<br />
	<form action="?t=save" method="post" name="form1" id="form1">
	<c:forEach var="bean" items="${roleList }">
	
	<c:forEach var="entry" items="${list }">
		<c:if test="${bean.action_type==entry.key }">
		<input type="checkbox" name="role_value" value="${entry.key }" checked="checked" />${entry.value }
		</c:if>
		<c:if test="${bean.action_type!=entry.key }">
		<input type="checkbox" name="role_value" value="${entry.key }" />${entry.value }
		</c:if>
	</c:forEach>
	<br />
	</c:forEach>
	<input type="submit" value="Save" />
	</form>
	
	<br />
	角色类型：${bean.role_type==1?"系统类型":"普通类型" }
	<br /> <hr />
	${roleName }
	<br />
	<%-- ${roleBean.manager_role_values==null?"空的":"不是空的也特么不是null" }  ${roleBean.manager_role_values }<br /> --%>
	<c:forEach var="bean" items="${roleBean.manager_role_values }">
	id:${bean.id } role_id:${bean.role_id } nav_id:${bean.nav_id } action_type: ${bean.action_type }
	
	
	   <br />
	
	</c:forEach>
	<hr />
	
	
	
	
	
	
	
	
	
	
	<hr />
	<c:forEach var="navBean" items="${navList }">
	<dl>
	<c:if test="${navBean.class_layer==1 }">
	<dt>
	${navBean.title } (${navBean.id }) 
	</dt>
	</c:if>
	
	
	<c:if test="${navBean.class_layer==2 }">
	<dl>
	
	<ul>
	<li>
	<a href="${navBean.linkurl }">${navBean.title }</a>(${navBean.id }) 
	</li>
	</ul>
	
	</dl>
	</c:if>
	
	</dl>
	<hr />
	
	</c:forEach>
	
	
	
	
</body>
</html>
